package com.gkt.ec.cms.activity.service;

import com.github.pagehelper.PageInfo;
import com.gkt.ec.cms.activity.dao.CompanyDao;
import com.gkt.ec.cms.activity.model.domain.CompanyEntity;
import com.gkt.ec.cms.activity.model.pojo.SearchCompanyVO;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Huzl
 * @version 1.0.0
 */
@Service
public class CompanyService {

    @Autowired
    CompanyDao companyDao;

    public PageInfo<CompanyEntity> queryAll(SearchCompanyVO searchCondition, int offset, int max) {
        List<CompanyEntity> companyEntityList = companyDao.queryAll(searchCondition, new RowBounds(offset, max));
        return new PageInfo<CompanyEntity>(companyEntityList);
    }

    public PageInfo<CompanyEntity> querySelectedCompany(SearchCompanyVO searchCondition, int offset, int max) {
        List<CompanyEntity> companyEntityList = companyDao.querySelectedCompany(searchCondition, new RowBounds(offset, max));
        return new PageInfo<CompanyEntity>(companyEntityList);
    }

    public PageInfo<CompanyEntity> querySelectCompany(SearchCompanyVO searchCondition, int offset, int max) {
        List<CompanyEntity> companyEntityList = companyDao.querySelectCompany(searchCondition, new RowBounds(offset, max));
        return new PageInfo<CompanyEntity>(companyEntityList);
    }


    @Transactional
    public void save(CompanyEntity companyEntity) {
        if (companyEntity.getId() == null)
            companyDao.insert(companyEntity);
        else
            companyDao.update(companyEntity);
    }

    @Transactional
    public int deleteAll(List<Long> ids) {
        return companyDao.deleteAll(ids);
    }

    public CompanyEntity get(Long id) {
        return companyDao.get(id);
    }

    public List<CompanyEntity> queryCompanyByName(String companyName) {
        return companyDao.queryCompanyByName(companyName);
    }
}
